<template>
	<view>
		<view class="margin-top-xs cu-list menu">
			<view class="cu-item arrow" @tap="goSetting(0)">
				<view class="content">支付宝</view>
				<text class="text-gray text-sm">{{ cnyAddress.address | addressText }}</text>
			</view>
			<!-- 审核模式不显示 -->
			<view class="cu-item arrow" @tap="goSetting(1)" v-if="!$store.state.checkMode">
				<view class="content">BTC</view>
				<text class="text-gray text-sm">{{ btcAddress.address | addressText }}</text>
			</view>
			<!-- 审核模式不显示 -->
			<view class="cu-item arrow" @tap="goSetting(2)" v-if="!$store.state.checkMode">
				<view class="content">ETH</view>
				<text class="text-gray text-sm">{{ ethAddress.address | addressText }}</text>
			</view>
			<navigator class="cu-item arrow" hover-class="none" url="settingpayPassword?t=0">
				<view class="content">提现密码</view>
				<text class="text-gray text-sm">********</text>
			</navigator>
		</view>
		<loading :loadModal="loadModal"></loading>
	</view>
</template>

<script>
var _self; //this容器
export default {
	data() {
		return {
			cnyAddress: { id: '', address: '', name: '', remarks: '', payPassword: '' },
			btcAddress: { id: '', address: '', name: '', remarks: '', payPassword: '' },
			ethAddress: { id: '', address: '', name: '', remarks: '', payPassword: '' },
			setPayPassword: false, //是否设置了提现密码
			loadModal: false //蒙层
		};
	},
	onLoad(options) {
		_self = this;
		_self.getAddressList();
		_self.getPayPassword();
		//用户名修改监听
		_self.$onFire.on('withdrawListener', function(id, name, address, remarks, type) {
			_self.changeContent(id, name, address, remarks, type);
		});
	},
	methods: {
		getAddressList() {
			_self.$http.httpRequest('userWithdrawalAddress/userId', null, true).then(res => {
				if (res._tranStatus) {
					let tmplist = res._data.list;
					if (tmplist) {
						tmplist.forEach(item => {
							if (item.currency == 'ETH') {
								_self.ethAddress.id = item.id;
								_self.ethAddress.name = item.name;
								_self.ethAddress.address = item.address;
								_self.ethAddress.remarks = item.remarks;
								_self.ethAddress.payPassword = item.payPassword;
							} else if (item.currency == 'BTC') {
								_self.btcAddress.id = item.id;
								_self.btcAddress.name = item.name;
								_self.btcAddress.address = item.address;
								_self.btcAddress.remarks = item.remarks;
								_self.btcAddress.payPassword = item.payPassword;
							} else {
								_self.cnyAddress.id = item.id;
								_self.cnyAddress.name = item.name;
								_self.cnyAddress.address = item.address;
								_self.cnyAddress.remarks = item.remarks;
								_self.cnyAddress.payPassword = item.payPassword;
							}
						});
					}
				}
			});
		},
		//是否设置提现密码
		getPayPassword() {
			_self.$http.httpRequest('user/isSetPayPassword', null, true).then(res => {
				if (res._tranStatus) {
					_self.setPayPassword = res._data.setPayPassword;
				}
			});
		},
		goSetting(type) {
			let tmpUrl = '';
			if (type == 0) {
				tmpUrl = 'settingWithdraw?s=u&type=0&cnt=' + encodeURIComponent(JSON.stringify(_self.cnyAddress));
			} else if (type == 1) {
				tmpUrl = 'settingWithdraw?s=u&type=1&cnt=' + encodeURIComponent(JSON.stringify(_self.btcAddress));
			} else {
				tmpUrl = 'settingWithdraw?s=u&type=2&cnt=' + encodeURIComponent(JSON.stringify(_self.ethAddress));
			}
			if (!_self.setPayPassword) {
				tmpUrl = 'settingpayPassword?t=1&cnt=' + encodeURIComponent(tmpUrl);
			}
			uni.navigateTo({
				url: tmpUrl
			});
		},
		changeContent(id, name, address, remarks, type) {
			_self.setPayPassword = true;
			if (type == 0) {
				_self.cnyAddress.id = id;
				_self.cnyAddress.name = decodeURIComponent(name);
				_self.cnyAddress.address = decodeURIComponent(address);
				_self.cnyAddress.remarks = decodeURIComponent(remarks);
			} else if (type == 1) {
				_self.btcAddress.id = id;
				_self.btcAddress.name = decodeURIComponent(name);
				_self.btcAddress.address = decodeURIComponent(address);
				_self.btcAddress.remarks = decodeURIComponent(remarks);
			} else {
				_self.ethAddress.id = id;
				_self.ethAddress.name = decodeURIComponent(name);
				_self.ethAddress.address = decodeURIComponent(address);
				_self.ethAddress.remarks = decodeURIComponent(remarks);
			}
		}
	},
	filters: {
		addressText: function(address) {
			return address == '' ? '设置' : address;
		}
	},
	onUnload() {
		this.$onFire.off();
	}
};
</script>

<style></style>
